//
//  UIScrollViewExtension.swift
//  Common
//
//  Created by 我骑着蜗牛走天下 on 2025/10/30.
//

import UIKit

extension UIScrollView {
    
    // 需要主动调用
    /// 让 scrollView 的 panGestureRecognizer 依赖导航控制器的侧滑返回手势失败后才触发，实现侧滑返回优先
    public func prioritizeInteractivePopGestureRecognizer() {
        guard let navController = getNavigationVC else { return }
        guard let gestureRecognizers = navController.view.gestureRecognizers else { return }

        for gestureRecognizer in gestureRecognizers {
            if gestureRecognizer is UIScreenEdgePanGestureRecognizer {
                // scrollView 的 panGesture 依赖侧滑手势失败后才触发
                self.panGestureRecognizer.require(toFail: gestureRecognizer)
            }
        }
    }
    
//    public func prioritizeInteractivePopGestureRecognizer() {
//        print("[日志] prioritizeInteractivePopGestureRecognizer 方法被调用")
//        
//        guard let navController = getNavigationVC else {
//            print("[日志] 获取导航控制器失败，getNavigationVC 返回 nil")
//            return
//        }
//        print("[日志] 找到导航控制器：\(navController)")
//
//        guard let gestureRecognizers = navController.view.gestureRecognizers else {
//            print("[日志] 导航控制器视图的 gestureRecognizers 为空")
//            return
//        }
//        print("[日志] 导航控制器视图上的手势识别器数量：\(gestureRecognizers.count)")
//
//        var foundEdgePan = false
//        for gestureRecognizer in gestureRecognizers {
//            if gestureRecognizer is UIScreenEdgePanGestureRecognizer {
//                foundEdgePan = true
//                print("[日志] 找到 UIScreenEdgePanGestureRecognizer：\(gestureRecognizer)")
//                self.panGestureRecognizer.require(toFail: gestureRecognizer)
//                print("[日志] 设置 scrollView 的 panGestureRecognizer 依赖侧滑手势失败后才触发")
//            }
//        }
//        if !foundEdgePan {
//            print("[日志] 未找到 UIScreenEdgePanGestureRecognizer")
//        }
//    }

    
}
